﻿using System;

namespace N2.Workflow.Items
{
	using ComponentModel;
	using Details;
	using Integrity;

	/// <summary>
	/// A single 1:1 mapping between
	/// a workflow definition and a ContentItem Type for which this workflow
	/// should be considered.
	/// </summary>
	[Definition]
	[RestrictParents(typeof(WorkflowRepository))]
	public sealed class WorkflowBindingByType: WorkflowBinding
	{
		#region Fields

		readonly PersistingTypePropertyHolder ItemTypeHolder;

		#endregion Fields

		#region Constructor

		public WorkflowBindingByType()
		{
			this.ItemTypeHolder = new PersistingTypePropertyHolder(this, "ItemTypeName", null);
		}

		#endregion Constructor

		#region Properties

		public override string IconUrl { get { return Constants.IconPath + "workflow_page.png"; } }
		
		/// <summary>
		/// A Type of Content Items, that should associated with a workflow definition
		/// </summary>
		[EditableTypeList("ItemType", 23, typeof(ContentItem))]
		public Type ItemType {
			get { return this.ItemTypeHolder.Value; }
			set { this.ItemTypeHolder.Value = value; }
		}
		
		#endregion Properties

		protected override string GetCaption()
		{
			return base.GetCaption() + " for typeof(" +
				(null != this.ItemType
					? this.ItemType.Name
					: "?")
				+ ")";
		}
	}
}
